package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.utils.GenerateNum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.YlFrontAccount;
import com.ruoyi.system.service.IYlFrontAccountService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 前端账户管理Controller
 * 
 * @author ruoyi
 * @date 2022-02-18
 */
@RestController
@RequestMapping("/frontaccount")
public class YlFrontAccountController extends BaseController
{
    @Autowired
    private IYlFrontAccountService ylFrontAccountService;

    /**
     * 查询前端账户管理列表.
     */
    @RequiresPermissions("ylsystem:frontaccount:list")
    @GetMapping("/list")
    public TableDataInfo list(YlFrontAccount ylFrontAccount)
    {
        startPage();
        List<YlFrontAccount> list = ylFrontAccountService.selectYlFrontAccountList(ylFrontAccount);
        return getDataTable(list);
    }

    /**
     * 导出前端账户管理列表
     */
    @RequiresPermissions("ylsystem:frontaccount:export")
    @Log(title = "前端账户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YlFrontAccount ylFrontAccount)
    {
        List<YlFrontAccount> list = ylFrontAccountService.selectYlFrontAccountList(ylFrontAccount);
        ExcelUtil<YlFrontAccount> util = new ExcelUtil<YlFrontAccount>(YlFrontAccount.class);
        util.exportExcel(response, list, "前端账户管理数据");
    }

    /**
     * 获取前端账户管理详细信息
     */
    @RequiresPermissions("ylsystem:frontaccount:query")
    @GetMapping(value = "/{accountId}")
    public AjaxResult getInfo(@PathVariable("accountId") Long accountId)
    {
        return AjaxResult.success(ylFrontAccountService.selectYlFrontAccountByAccountId(accountId));
    }

    /**
     * 新增前端账户管理
     */
    @RequiresPermissions("ylsystem:frontaccount:add")
    @Log(title = "前端账户管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YlFrontAccount ylFrontAccount)
    {
        ylFrontAccount.setAccountCardNumber(GenerateNum.generateOrder()+"");
        return toAjax(ylFrontAccountService.insertYlFrontAccount(ylFrontAccount));
    }

    /**
     * 修改前端账户管理
     */
    @RequiresPermissions("ylsystem:frontaccount:edit")
    @Log(title = "前端账户管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YlFrontAccount ylFrontAccount)
    {
        return toAjax(ylFrontAccountService.updateYlFrontAccount(ylFrontAccount));
    }

    /**
     * 删除前端账户管理
     */
    @RequiresPermissions("ylsystem:frontaccount:remove")
    @Log(title = "前端账户管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{accountIds}")
    public AjaxResult remove(@PathVariable Long[] accountIds)
    {
        return toAjax(ylFrontAccountService.deleteYlFrontAccountByAccountIds(accountIds));
    }


   @PostMapping("/findByfrontaccount")
    public  YlFrontAccount aaa(@RequestBody  YlFrontAccount ylFrontAccount){
       YlFrontAccount ylFrontAccount1 =  ylFrontAccountService.selectYlFrontAccountByAccount(ylFrontAccount);
       return ylFrontAccount1;
    }

}
